home *** CD-ROM | disk | FTP | other *** search
/ PC Format (PL) 2008 February / PC_Format_022008.iso / Internet / Mozilla Thunderbird wtyczki / lightning-0.7-tb-win.xpi / chrome / lightning.jar / content / lightning / sun-messenger-overlay-sidebar.js < prev    next >
Encoding:
Text File  |  2007-09-27  |  5.1 KB  |  130 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is Sun Microsystems code.
  15.  *
  16.  * The Initial Developer of the Original Code is Sun Microsystems.
  17.  * Portions created by the Initial Developer are Copyright (C) 2006
  18.  * the Initial Developer. All Rights Reserved.
  19.  *
  20.  * Contributor(s):
  21.  *   Thomas Benisch <thomas.benisch@sun.com>
  22.  *   Philipp Kewisch <mozilla@kewis.ch>
  23.  *
  24.  * Alternatively, the contents of this file may be used under the terms of
  25.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  26.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.  * in which case the provisions of the GPL or the LGPL are applicable instead
  28.  * of those above. If you wish to allow use of your version of this file only
  29.  * under the terms of either the GPL or the LGPL, and not to allow others to
  30.  * use your version of this file under the terms of the MPL, indicate your
  31.  * decision by deleting the provisions above and replace them with the notice
  32.  * and other provisions required by the GPL or the LGPL. If you do not delete
  33.  * the provisions above, a recipient may use your version of this file under
  34.  * the terms of any one of the MPL, the GPL or the LGPL.
  35.  *
  36.  * ***** END LICENSE BLOCK ***** */
  37.  
  38. const FIRST_DELAY_STARTUP = 100;
  39. const FIRST_DELAY_RESCHEDULE = 100;
  40. const FIRST_DELAY_REGISTER = 10000;
  41. const FIRST_DELAY_UNREGISTER = 0;
  42. const REPEAT_DELAY = 180000;
  43.  
  44. var sideBarOperationListener = {
  45.     onOperationComplete: function sBOL_onOperationComplete(aCalendar,
  46.                                                            aStatus,
  47.                                                            aOperationType,
  48.                                                            aId,
  49.                                                            aDetail) {
  50.         if (!Components.isSuccessCode(aStatus)) {
  51.             var invitationsBox = document.getElementById("invitations");
  52.             invitationsBox.setAttribute("hidden", "true");
  53.         }
  54.     },
  55.  
  56.     onGetResult: function sBOL_onGetResult(aCalendar,
  57.                                            aStatus,
  58.                                            aItemType,
  59.                                            aDetail,
  60.                                            aCount,
  61.                                            aItems) {
  62.         if (!Components.isSuccessCode(aStatus)) {
  63.             return;
  64.         }
  65.         var invitationsBox = document.getElementById("invitations");
  66.         var value = invitationsLabel + " (" + aCount + ")";
  67.         invitationsBox.setAttribute("value", value);
  68.         invitationsBox.removeAttribute("hidden");
  69.     }
  70. };
  71.  
  72. var sideBarCalendarManagerObserver = {
  73.     mSideBar: this,
  74.  
  75.     onCalendarRegistered: function cMO_onCalendarRegistered(aCalendar) {
  76.         this.mSideBar.rescheduleInvitationsUpdate(FIRST_DELAY_REGISTER,
  77.                                                   REPEAT_DELAY);
  78.     },
  79.  
  80.     onCalendarUnregistering: function cMO_onCalendarUnregistering(aCalendar) {
  81.         this.mSideBar.rescheduleInvitationsUpdate(FIRST_DELAY_UNREGISTER,
  82.                                                   REPEAT_DELAY);
  83.     },
  84.  
  85.     onCalendarDeleting: function cMO_onCalendarDeleting(aCalendar) {
  86.     },
  87.  
  88.     onCalendarPrefChanged: function cMO_onCalendarPrefSet(aCalendar,
  89.                                                       aName,
  90.                                                       aValue) {
  91.     },
  92.  
  93.     onCalendarPrefDeleting: function cMO_onCalendarPrefSet(aCalendar, aName) {
  94.     }
  95. };
  96.  
  97. function onLoad() {
  98.     scheduleInvitationsUpdate(FIRST_DELAY_STARTUP, REPEAT_DELAY);
  99.     getCalendarManager().addObserver(sideBarCalendarManagerObserver);
  100.     document.addEventListener("unload", onUnload, true);
  101. }
  102.  
  103. function onUnload() {
  104.     document.removeEventListener("unload", onUnload, true);
  105.     getCalendarManager().removeObserver(sideBarCalendarManagerObserver);
  106. }
  107.  
  108. function scheduleInvitationsUpdate(firstDelay, repeatDelay) {
  109.     getInvitationsManager().scheduleInvitationsUpdate(firstDelay,
  110.                                                       repeatDelay,
  111.                                                       sideBarOperationListener);
  112. }
  113.  
  114. function rescheduleInvitationsUpdate(firstDelay, repeatDelay) {
  115.     getInvitationsManager().cancelInvitationsUpdate();
  116.     scheduleInvitationsUpdate(firstDelay, repeatDelay);
  117. }
  118.  
  119. function openInvitationsDialog() {
  120.     getInvitationsManager().cancelInvitationsUpdate();
  121.     getInvitationsManager().openInvitationsDialog(
  122.         sideBarOperationListener,
  123.         function oiD_callback() {
  124.             scheduleInvitationsUpdate(FIRST_DELAY_RESCHEDULE,
  125.                                      REPEAT_DELAY);
  126.         });
  127. }
  128.  
  129. onLoad();
  130.